<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="../../../../assets/libs/jquery/jquery-3.6.1.min.js"></script>
  <style>
    * {
      padding: 0;
      margin: 0;
    }

    html {
      height: 200vh;
      background-image: linear-gradient(black, white);
    }

    div {
      width: 200px;
      height: 200px;
      margin: 100vh auto 0;
      background-color: white;
    }
  </style>
</head>

<body>
  <div></div>

  <script>
    // 获取相对于文档的位置
    const offset = $('div').offset()
    console.log(
      offset.top,
      offset.left
    )

    // 设置相对于文档的位置
    $('div').offset({
      top: 100,
      left: 100
    })
  </script>
</body>

</html>